{
"cells": [
{
"cell_type": "markdown",
"id": "57a92274",
"metadata": {},
"source": [
"# Load, Fuel Mix, and LMP Data\n",
"\n",
"This notebook walk through how to use `gridstatus` to access to the data availabe on [OASIS](http://oasis.caiso.com/).\n",
"\n",
"While we will be using CAISO in this example, most of this API will also work with all other ISOs."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "3599dfce",
"metadata": {},
"outputs": [],
"source": [
"import gridstatus\n",
"import pandas as pd\n",
"import plotly.express as px"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "854ac803",
"metadata": {},
"outputs": [],
"source": [
"caiso = gridstatus.CAISO()"
]
},
{
"cell_type": "markdown",
"id": "4612c2d0",
"metadata": {},
"source": [
"## Historical Fuel Mix"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d35b27ed",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1696/1696 [15:48<00:00, 1.79it/s]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"April 10, 2018\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"mix_df = caiso.get_fuel_mix(start, end=end, verbose=False)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "662f53d4",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"hourly_mix = mix_df.set_index(\"Time\").resample(\"H\").mean()\n",
"monthly_mix = hourly_mix.resample(\"MS\").sum().reset_index()[1:-1]\n",
"top_sources = monthly_mix[monthly_mix.columns[1:]].sum().sort_values(ascending=False).index.tolist()\n",
"fig = px.bar(monthly_mix, x=\"Time\", y=top_sources, title=\"Fuel Mix by Month - CAISO\")\n",
"fig.show(\"svg\", width = 1200, height = 600)"
]
},
{
"cell_type": "markdown",
"id": "bb652292",
"metadata": {},
"source": [
"## Historical Load "
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "27098731",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1696/1696 [13:27<00:00, 2.10it/s]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"April 10, 2018\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"load_df = caiso.get_load(start, end=end)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "4eb4c3e3",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"hourly_load = load_df.set_index(\"Time\").resample(\"H\").mean()\n",
"monthly_load = hourly_load.resample(\"MS\").sum().reset_index()[1:-1]\n",
"fig = px.line(monthly_load, x=\"Time\", y=\"Load\", title=\"Monthly Load - CAISO\")\n",
"fig.show(\"svg\", width = 1200, height = 600)"
]
},
{
"cell_type": "markdown",
"id": "7193787c",
"metadata": {},
"source": [
"## Historical Locational Marginal Pricing (LMP)\n",
"\n",
"You can supply whatever nodes or market you'd like, but for now let's download data for 3 trading hubs in the Day Head Hourly Market. \n",
"\n",
"Note: CAISO only provides last 39 months of data."
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "86cb97a7",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 35/35 [22:04<00:00, 37.85s/it]\n"
]
}
],
"source": [
"start = pd.Timestamp(\"Jan 1, 2020\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"locations = ['TH_NP15_GEN-APND', 'TH_SP15_GEN-APND', 'TH_ZP26_GEN-APND']\n",
"\n",
"lmp_df = caiso.get_lmp(start=start, \n",
" end=end,\n",
" market='DAY_AHEAD_HOURLY', \n",
" locations=locations, \n",
" sleep=5)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "39c891f9",
"metadata": {},
"outputs": [
{
"data": {
"image/svg+xml": ""
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"negative_lmps = lmp_df[lmp_df[\"LMP\"] < 0].set_index(\"Time\")\n",
"negative_per_month = negative_lmps.groupby(\"Location\").resample(\"MS\")[\"LMP\"].count().reset_index()\n",
"fig = px.bar(negative_per_month, x=\"Time\", y=\"LMP\", title=\"Negative LMPs per Month - CAISO\", color=\"Location\")\n",
"fig.update_yaxes(title=\"Number of Negative LMPs\")\n",
"fig.show(\"svg\", width = 1200, height = 600)"
]
},
{
"cell_type": "markdown",
"id": "10f2ba2a",
"metadata": {},
"source": [
"## Gas Prices\n",
"\n",
"CAISO also publish information about gas prices and greenhouse gas allownces that we will download"
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "917a3e07",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 11/11 [01:03<00:00, 5.78s/it]\n"
]
}
],
"source": [
"start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"gas_price_df = caiso.get_gas_prices(start=start, end=end, fuel_region_id=\"FRPGE2GHG\")"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "f4168867",
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 11/11 [01:03<00:00, 5.75s/it]\n"
]
}
],
"source": [
"start = start = pd.Timestamp(\"Jan 01, 2022\").normalize()\n",
"end = pd.Timestamp.now().normalize()\n",
"\n",
"ghg_df = caiso.get_ghg_allowance(start=start, end=end)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3.10.2 64-bit ('gridstatus')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.2"
},
"vscode": {
"interpreter": {
"hash": "49f14642123d0cc1afa9fa45716ed5f1e915189c28b01efe02a8b7ec3c0a3fce"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}